import 'package:flutter/material.dart';
import 'package:hkzf_flutter/config.dart';
import 'package:hkzf_flutter/dio/room_item.dart';
import 'package:hkzf_flutter/pages/search/room/room_item.dart';
import 'package:hkzf_flutter/widgets/common_image.dart';
import 'package:hkzf_flutter/widgets/common_tag.dart';
// 房源列表子项页面结构

class RoomListItem extends StatelessWidget {
  final RoomItem data;
  RoomListItem({super.key,RoomItem? data}):data = data ?? roomList [0];

  @override
  Widget build(BuildContext context) {
    // 处理房屋图片路径
    var imageUrl = data.houseImg.startsWith('http') ?
    data.houseImg : Config.BaseUrl + data.houseImg;
    return GestureDetector(
      behavior: HitTestBehavior.translucent,// 点击事件穿透
      onTap: (){
        print('data:${data.id}');
         Navigator.of(context).pushNamed('/roomDetail/${data.id}');
      },
      child: Container(
          padding: const EdgeInsets.only(left: 10.0,right: 10.0,bottom: 10.0),
          child: Row(
            children: [
              CommonImage(src: imageUrl,width: 132.5,height: 100.0,),
              const Padding(padding: EdgeInsets.all(10.0)),
              Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,// 设置子组件的横向对齐方式
                    children: [
                      Text(data.title,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(
                        fontSize: 16.0,
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
    
                        ),
                      ),
                      Text(
                        data.desc,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Wrap(
                        children: data.tags.map((pre)=>CommonTag.fromTitle(pre)).toList(),
                      ),
                      Text('${data.price} 元/每月',style: const TextStyle(
                        fontSize: 16.0,
                        color: Colors.orange,
                        fontWeight: FontWeight.bold
                      ),)
                    ]
                  )
              )
            ],
          ),
       ),
    );
  }
}
